package service;

import com.jfinal.plugin.activerecord.Page;
import model.StationVoltageInfo;

public class StationService {
    private StationVoltageInfo dao = new StationVoltageInfo().dao();

    public Page<StationVoltageInfo> search(String zk_bdz_id, String zk_bdz_name, String line_name, int pageNumber, int pageSize) {
        String selectSql = "SELECT *";
        String fromSql = "FROM mz_zk_d5k_voltage_bak WHERE 1=1";
        if (zk_bdz_id != null && !"".equals(zk_bdz_id)) {
            fromSql += " AND zk_bdz_id LIKE '%" + zk_bdz_id + "%'";
        }
        if (zk_bdz_name != null && !"".equals(zk_bdz_name)) {
            fromSql += " AND zk_bdz_name LIKE '%" + zk_bdz_name + "%'";
        }
        if (line_name != null && !"".equals(line_name)) {
            fromSql += " AND line_name LIKE '%" + line_name + "%'";
        }
        Page<StationVoltageInfo> infoPage = dao.paginate(pageNumber, pageSize, selectSql, fromSql);
        if (infoPage.getList().size() == 0) {
            infoPage = dao.paginate(pageNumber - 1, pageSize, selectSql, fromSql);
        }
        return infoPage;
    }

    public void batchDelete(String[] ids) {
        for (String id : ids) {
            dao.deleteById(id);
        }
    }

    public void deleteById(String id) {
        dao.deleteById(id);
    }

    public void save(StationVoltageInfo stationInfo) {
        stationInfo.save();
    }

    public void update(StationVoltageInfo stationInfo) {
        stationInfo.update();
    }

}
